/**
 * Author: wangjunfu
 * Date: 2018-12-22
 * Description: 数据分析，设置分类
 */

function setCatalog(pertype, modeltype, setid, cateid) {
    $.ajax({
        url: "/basic/newscate/setCatalog",
        type: "POST",
        data: {pertype: pertype, modeltype: modeltype, setid: setid, cateid: cateid},
        async: false,
        error: function (request) {
            //error
        },
        success: function (data) {
            $('.setdata-content-narrow').html(data);
            $('#setCatalogId').selectpicker('refresh');
        }
    });
}

// 保存分类
function doSetCatalog() {
    var setid = $("#setId").val();
    var pertype = $("#perType").val();
    var cateid = $('#setCatalogId').find('option:selected').val();
    var catename = $('#setCatalogId').find('option:selected').text();
    catename = catename.replace("|┄ ", "");

    $.ajax({
        url: "/basic/newscate/doSetCatalog",
        type: "POST",
        data: {cateid: cateid, setid: setid, pertype: pertype},
        dataType: 'json',
        async: false,
        error: function (request) {
            showInfoAlert("服务器连接失败，请检查网络环境！", null);
        },
        success: function (data) {
            showInfoAlert(data.returnMessage, null);

            if (data.returnCode === 1) {
                $("#cate-" + setid).text(catename);
                $("#custom-narrow-modal").modal("hide");
            }
        }
    });
}